package com.guoliang.orderService.service.impl;

import com.guoliang.commonUtils.entity.CourseFrontVo;
import com.guoliang.commonUtils.entity.UcenterMember;
import com.guoliang.orderService.entity.Order;
import com.guoliang.orderService.mapper.OrderMapper;
import com.guoliang.orderService.service.CourseClient;
import com.guoliang.orderService.service.OrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guoliang.orderService.service.UcenterClient;
import com.guoliang.orderService.utils.OrderNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 订单 服务实现类
 * </p>
 *
 * @author leo
 * @since 2023-01-31
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Resource
    private UcenterClient ucenterClient;
    @Resource
    private CourseClient courseClient;
    @Override
    public String createOrder(String courseId, String memberId) {
        UcenterMember member = ucenterClient.getMember(memberId);
        CourseFrontVo courseFrontVo = courseClient.orderGetCourse(courseId);
        Order order = new Order();
        order.setOrderNo(OrderNoUtil.getOrderNo());
        order.setCourseId(courseFrontVo.getId());
        order.setCourseCover(courseFrontVo.getCover());
        order.setCourseTitle(courseFrontVo.getTitle());
        order.setMemberId(member.getId());
        order.setNickname(member.getNickname());
        order.setMail(member.getMail());
        order.setTeacherName(courseFrontVo.getTeacherName());
        order.setTotalFee(courseFrontVo.getPrice());
        order.setStatus(0);
        order.setPayType(1);
        baseMapper.insert(order);
        return order.getOrderNo();
    }
}
